#!/usr/bin/python
# -*-  coding:utf-8 -*-

def max(a, b):
    if a > b:
        return  a
    else:
        return b
print(max(10, 20))
print(max(190, 20))

def max(a, b):
    if isinstance(a, int) and isinstance(b, int):
        if a > b:
            return a
        else:
            return b
    else:
        return None

print(max("zzz", 10))
print(max("zzz", "bbbb"))
print(max(20, 10))

def min(a, b):
    return None

print(min(10, 320))

print("--------函数返回值返回两个值------------------")
def max_and_min(a, b):
    if a > b:
        return a, b
    else:
        return b, a

print(type(max_and_min(10, 30)))
print(max_and_min(10, 30)[0])
print(max_and_min(10, 30)[1])

print("---------------------缺省函数参数-----------------")
def power(a, b=2):
    return a**b

print(power(10))
print(power(10, 10))

print("------------------阶乘------------------------")
def fn(n):
    if n == 1:
        return 1
    else:
        return n*fn(n-1)

print(fn(5))

print("---------斐波那契额数列--------------------")
def fb(n):
    if n == 1 or n == 2:
        return 1
    else:
        return fb(n-1)+ fb(n-2)

print(fb(6))

print("----------字典遍历----------------")
dict1 = {"aa":1, "bb":2, "cc":3, "dd":4}

for key in  dict1 :
    print(key, dict1[key], end="\t")
print()

print("-----字符数组遍历--------------")
for c in "刘德华":
    print(c)

print("-----元组遍历--------------")
list1 = [(1, 2), (3, 4), (5, 6), (7, 8)]
print(list1)
print(type(list1))
print(type(list1[0]))

for x, y in list1:
    print("(", x, y,"),", end=" ")
print()


print("-----字典遍历-------------")
for x, y in  dict1.items():
    print(x, y, end="\t")
print()

print(list(range(10)))

for a in list(range(10))[1:10]:
    print(a, end=" ")
print()

result1 = [str(x) + ', hello'  for x in list(range(10))[::2]]
print(result1)

result1 = [str(x)+""+"hello"  for x in list(range(10))[::2]]
print(result1)


l2 = ["a","b","c"]
print(l2)
aa = "\t".join(l2)
print(aa)
print(type(aa))


result3 = [str(x) + ",hello" for x in  list(range(10000))[1:]]
print("result3", result3)

result4 = (str(x) + ",hello" for x in  list(range(10000))[1:])
print(result4)

print(result4)
print(next(result4))   # 从生成器中取出一个值
print(next(result4))   # 从生成器中取出一个值
print(next(result4))   # 从生成器中取出一个值
print(next(result4))   # 从生成器中取出一个值
print(next(result4))   # 从生成器中取出一个值     迭代器
print(result4)
print(next(result4))


def print_list(a):
    for i in range(len(a)):
        print(a[i])
    return 3
print(print_list([1,2,3,"a","123"]))